# Maintainer: Martin Diehl <aur@martin-diehl.net>
# Contributor: Alad Wenter <alad@archlinux.org>
# Contributor: Jingbei Li <i@jingbei.li>
# Contributor: Simon Pintarelli <simon.pintarelli@gmail.com>
# Contributor: Feng Wang <wanng.fenng@gmail.com>
# Contributor (msys): Rafal Brzegowy <rafal.brzegowy@yahoo.com>

_realname=trilinos
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=13.2.0
_pkgver=${pkgver//./-}
pkgrel=1
pkgdesc='Algorithms for the solution of large-scale scientific problems" (mingw-w64)'
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64')
depends=("${MINGW_PACKAGE_PREFIX}-python"
         "${MINGW_PACKAGE_PREFIX}-openblas"
         "${MINGW_PACKAGE_PREFIX}-boost"
	 "${MINGW_PACKAGE_PREFIX}-netcdf"
	 "${MINGW_PACKAGE_PREFIX}-matio"
	 "${MINGW_PACKAGE_PREFIX}-hdf5"
	 "${MINGW_PACKAGE_PREFIX}-msmpi")
makedepends=("unzip"
             "${MINGW_PACKAGE_PREFIX}-msmpi"
             "${MINGW_PACKAGE_PREFIX}-perl"
             "${MINGW_PACKAGE_PREFIX}-ninja"
	     "${MINGW_PACKAGE_PREFIX}-openblas"
             "${MINGW_PACKAGE_PREFIX}-cmake"
	     "${MINGW_PACKAGE_PREFIX}-bc"
	     "${MINGW_PACKAGE_PREFIX}-python-numpy")
checkdepends=("${MINGW_PACKAGE_PREFIX}-cmake")
optdepends=("${MINGW_PACKAGE_PREFIX}-seacas")
license=('LGPL3')
url="http://trilinos.org"
source=("https://github.com/${_realname}/Trilinos/archive/refs/tags/${_realname}-release-${_pkgver}.zip")
sha256sums=('5224AD60B94FC1100A616A5AA37F14E4673FEAEFC94451751AF2A0E672029D2D')
noextract=("${_realname}-release-${_pkgver}.zip") # bsdtar could not unpack this archive

prepare() {  
  unzip -oq trilinos-release-$_pkgver.zip -d ${srcdir}
}

build() {
  [[ -d "${srcdir}/build-${MINGW_CHOST}" ]] && rm -rf "${srcdir}/build-${MINGW_CHOST}"
  mkdir -p "${srcdir}/build-${MINGW_CHOST}" && cd "${srcdir}/build-${MINGW_CHOST}"

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
    ${MINGW_PREFIX}/bin/cmake \
      -GNinja \
      -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
      -DCMAKE_BUILD_TYPE=Release \
      -DBLAS_LIBRARY_NAMES="openblas" \
      -DLAPACK_LIBRARY_NAMES="openblas" \
      -DMPI_USE_COMPILER_WRAPPERS=ON \
      -DTrilinos_ENABLE_ALL_OPTIONAL_PACKAGES=ON \
      -DTrilinos_ENABLE_ALL_PACKAGES=ON \
      -DTrilinos_ENABLE_SEACAS=OFF \
      -DTrilinos_ENABLE_Zoltan=OFF \
      -DTrilinos_ENABLE_Teuchos=OFF \
      -DTrilinos_ENABLE_Kokkos=OFF \
      -DTrilinos_ENABLE_Epetra=OFF \
      ../Trilinos-${_realname}-release-${_pkgver}

  ${MINGW_PREFIX}/bin/cmake --build .
}

package() {
  cd "${srcdir}/build-${MINGW_CHOST}"
  DESTDIR=${pkgdir} cmake --build . --target install
  install -Dm644 ${srcdir}/Trilinos-${_realname}-release-${_pkgver}/LICENSE ${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE  
}
